package com.tuosha.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.tuosha.dao.JieQianJqCatDao;
import com.tuosha.dao.JqCatsDao;
import com.tuosha.model.JieQianJqCatEntity;
import com.tuosha.model.JqCatsEntity;
import com.tuosha.service.JieQianJqCatService;
import com.tuosha.service.JqCatsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;
import java.util.Map;


@Service("jqCatsServiceImpl")
public class JqCatsServiceImpl implements JqCatsService {
	@Autowired
	private JqCatsDao jqCatsDao;

	@Autowired
	private JieQianJqCatDao jieQianJqCatDao;

	@Autowired
	private JieQianJqCatService jieQianJqCatServiceImpl;


	@Override
	public JqCatsEntity queryObject(Integer id){
		return jqCatsDao.queryObject(id);
	}
	
	@Override
	public List<JqCatsEntity> queryList(Map<String, Object> map){
		return jqCatsDao.queryList(map);
	}
	
	@Override
	public int queryTotal(Map<String, Object> map){
		return jqCatsDao.queryTotal(map);
	}
	
	@Override
	public void save(JqCatsEntity jqCats){
		jqCatsDao.save(jqCats);
	}
	
	@Override
	public int update(JqCatsEntity jqCats){
		return jqCatsDao.update(jqCats);
	}
	
	@Override
	public int delete(Integer id){
		return jqCatsDao.delete(id);
	}
	
	@Override
	public int deleteBatch(Integer[] ids){
		return jqCatsDao.deleteBatch(ids);
	}

	public int delById(Integer id){
		Date date=new Date();
		JqCatsEntity ties= new JqCatsEntity();
		ties.setId(id);
		ties.setDeletedAt(date);
		//删除关联关系表信息
		List<JieQianJqCatEntity> jqcats = jieQianJqCatDao.queryJQList(id);
		if (jqcats.size()!=0) {
			for (JieQianJqCatEntity cat : jqcats) {
				jieQianJqCatServiceImpl.delById(cat.getId());
			}
		}
		return jqCatsDao.update(ties);
	}

	public int delPatch(String  tiestr){
		String[] strs = tiestr.split(",");
		if(strs!=null&&strs.length>0){
			for (String str : strs) {
				delById(Integer.parseInt(str));
			}
		}
		return 0;
	}

	public JqCatsEntity queryName(String name){
		return jqCatsDao.queryName(name);
	}

	@Override
	public List<JqCatsEntity> queryAllList(){
		return jqCatsDao.queryAllList();
	}



}
